<template>
    <div>
        <h2>会告添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">会告标题</td>
                    <td><input type="text" v-model="quertInfo.witeTitle"/></td>
                </tr>
                <tr>
                    <td align="right">会告内容</td>
                    <td> <textarea  cols="50" rows="5" v-model="quertInfo.witeDesc"></textarea></td>
                </tr>
                <tr>
                    <td align="right">门店图片</td>
                    <td>
                        <input type="file" @change="getphoto"/>
                        <img :src="quertInfo.photo" alt="" width="100" height="100" />
                    </td>
                </tr>
                <tr>
                    <td align="right">会告状态</td>
                    <td><input type="radio" name="state" :value="1" v-model="quertInfo.state"/>启用
                        <input type="radio" name="state" :value="0" v-model="quertInfo.state"/>隐藏
                    
                    </td>
                </tr>
                <tr>
                    <td align="right">会告类型</td>
                    <td>
                        <select v-model="quertInfo.witeType">
                            <option value="">请选择</option>
                            <option :value="1">服务协议</option>
                            <option :value="2">水电协议</option>
                            <option :value="3">安全协议</option>
                        
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="提交" @click="ok" class="btn btn-primary" />
                    
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref, reactive,onMounted} from 'vue'
import {useRouter, useRoute} from 'vue-router'
import axios from 'axios';
let router = useRouter()
let route = useRoute()
//图片上传
const getphoto = (e:any)=>{
    let file = e.target.files[0]
    let formdata= new FormData();
    formdata.append("file",file)
    axios({
        url:"/api/Photo/GetPhoto",
        method:"post",
        data:formdata
    })
    .then((res)=>{
        console.log(res)
        quertInfo.photo = res.data
    })
    .catch((err)=>{
        console.log(err)
    })
}
let quertInfo=reactive({
   
  witeTitle: "",
  witeDesc: "",
  photo: "",
  state: 1,
  witeType: "",
})
const ok = () => {
    axios({
        url: "/api/Willtell/WillteAdd",
        method: "post",
        data: quertInfo
    })
    .then((res) => {
        console.log(res);
        if (res.data == 1) {
            alert("添加成功")
            router.push("/WiliteList")
        }
        else if(res.data==-1)
        {
            alert('会告标题已存在')
        }
        else{
            alert("添加失败")
        }
    })
}
</script>

<style scoped>

</style>